#include "stdafx.h"
#include "SamplerState.h"

namespace Reign
{namespace Video
{namespace D3D10
{
	#pragma region Properties
	D3D10_SAMPLER_DESC* SamplerStateDesc::Desc::get() {return desc;}
	#pragma endregion

	#pragma region Constructors
	SamplerStateDesc::SamplerStateDesc(SamplerStateTypes type)
	{
		null();
		desc = new D3D10_SAMPLER_DESC();
		switch (type)
		{
			case (SamplerStateTypes::Point_Wrap):
				desc->Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
				desc->AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
				desc->AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
				desc->AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
				desc->MipLODBias = 0.0f;
				desc->MaxAnisotropy = 1;
				desc->ComparisonFunc = D3D10_COMPARISON_NEVER;
				desc->BorderColor[0] = 0.0f;
				desc->BorderColor[1] = 0.0f;
				desc->BorderColor[2] = 0.0f;
				desc->BorderColor[3] = 0.0f;
				desc->MinLOD = 0.0f;
				desc->MaxLOD = D3D10_FLOAT32_MAX;
				break;

			case (SamplerStateTypes::Point_Clamp):
				desc->Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
				desc->AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
				desc->AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
				desc->AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
				desc->MipLODBias = 0.0f;
				desc->MaxAnisotropy = 1;
				desc->ComparisonFunc = D3D10_COMPARISON_NEVER;
				desc->BorderColor[0] = 0.0f;
				desc->BorderColor[1] = 0.0f;
				desc->BorderColor[2] = 0.0f;
				desc->BorderColor[3] = 0.0f;
				desc->MinLOD = 0.0f;
				desc->MaxLOD = D3D10_FLOAT32_MAX;
				break;

			case (SamplerStateTypes::Point_Border):
				desc->Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
				desc->AddressU = D3D10_TEXTURE_ADDRESS_BORDER;
				desc->AddressV = D3D10_TEXTURE_ADDRESS_BORDER;
				desc->AddressW = D3D10_TEXTURE_ADDRESS_BORDER;
				desc->MipLODBias = 0.0f;
				desc->MaxAnisotropy = 1;
				desc->ComparisonFunc = D3D10_COMPARISON_NEVER;
				desc->BorderColor[0] = 0.0f;
				desc->BorderColor[1] = 0.0f;
				desc->BorderColor[2] = 0.0f;
				desc->BorderColor[3] = 0.0f;
				desc->MinLOD = 0.0f;
				desc->MaxLOD = D3D10_FLOAT32_MAX;
				break;

			case (SamplerStateTypes::Linear_Wrap):
				desc->Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
				desc->AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
				desc->AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
				desc->AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
				desc->MipLODBias = 0.0f;
				desc->MaxAnisotropy = 1;
				desc->ComparisonFunc = D3D10_COMPARISON_NEVER;
				desc->BorderColor[0] = 0.0f;
				desc->BorderColor[1] = 0.0f;
				desc->BorderColor[2] = 0.0f;
				desc->BorderColor[3] = 0.0f;
				desc->MinLOD = 0.0f;
				desc->MaxLOD = D3D10_FLOAT32_MAX;
				break;

			case (SamplerStateTypes::Linear_Clamp):
				desc->Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
				desc->AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
				desc->AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
				desc->AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
				desc->MipLODBias = 0.0f;
				desc->MaxAnisotropy = 1;
				desc->ComparisonFunc = D3D10_COMPARISON_NEVER;
				desc->BorderColor[0] = 0.0f;
				desc->BorderColor[1] = 0.0f;
				desc->BorderColor[2] = 0.0f;
				desc->BorderColor[3] = 0.0f;
				desc->MinLOD = 0.0f;
				desc->MaxLOD = D3D10_FLOAT32_MAX;
				break;

			case (SamplerStateTypes::Linear_Border):
				desc->Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
				desc->AddressU = D3D10_TEXTURE_ADDRESS_BORDER;
				desc->AddressV = D3D10_TEXTURE_ADDRESS_BORDER;
				desc->AddressW = D3D10_TEXTURE_ADDRESS_BORDER;
				desc->MipLODBias = 0.0f;
				desc->MaxAnisotropy = 1;
				desc->ComparisonFunc = D3D10_COMPARISON_NEVER;
				desc->BorderColor[0] = 0.0f;
				desc->BorderColor[1] = 0.0f;
				desc->BorderColor[2] = 0.0f;
				desc->BorderColor[3] = 0.0f;
				desc->MinLOD = 0.0f;
				desc->MaxLOD = D3D10_FLOAT32_MAX;
				break;

			default:
				Debug::ThrowError(L"SamplerStateDesc", L"Unsuported SamplerStateType");
				break;
		}
	}

	SamplerStateDesc::~SamplerStateDesc()
	{
		if (desc) delete desc;
		null();
	}

	void SamplerStateDesc::null()
	{
		desc = 0;
	}
	#pragma endregion
}
}
}